package com.ehotting.edsta.simulation.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.ehotting.edsta.simulation.controller.SimulationWsController;
import com.ehotting.mqbd.api.bean.MQDataAble;
import com.ehotting.mqbd.zw.api.constants.ActionConstants;
import com.ehotting.mqbd.zw.api.domain.netty.ZwCommPacket;
import com.ehotting.mqbd.zw.client.mq.ZwMqActionServiceAble;
import lombok.extern.slf4j.Slf4j;
import org.jvnet.hk2.annotations.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
@Service
public class ZwMqActionService implements ZwMqActionServiceAble {

    @Autowired
    private SimulationWsController simulationWsController;

    @Override
    public void sendToClient(MQDataAble mqData) {
        log.info("response:{}",JSON.toJSONString(mqData.getResponse()));

        String agentId = mqData.getAgentId();
        log.info("agentId:{}",agentId);
        if(mqData.getResponse()==null){
            log.info("mqData.getResponse() is null,return.",mqData.getResponseString());
            return;
        }

        try {
            simulationWsController.sendUserMessage(JSON.toJSONString(mqData.getResponse(), SerializerFeature.DisableCircularReferenceDetect),mqData.getAgentId());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
